# @Author   : 懒羊羊
# @File     : day03_function.py
# @Time     : 2024/11/27 14:11

def huoDong(num):
    for i in range(num):
        age = int(input("请输入年龄："))

        if age > 40:
            print("你可以领鸡蛋！！！")
            if age < 50:
                print("你可以领10个")
            elif age < 60:
                print("你可以领20个")
            else:
                print("你可以领30个")
        elif age < 12:
            print("你可以领玩具")
        elif age < 24:
            print("你可以领钢笔")
        else:
            print("你可以领纸巾")


# huoDong(2)


# 不定长参数：* 不定长元组
# def yuanZu(*a):
#     print(a)
#
#
# yuanZu("不定长元组")
# yuanZu("不定长元组", "不定长")


# def ziDian(**b):
#     print(b)
#
#
# ziDian(name="懒羊羊", age=22)


# def my_add(num1, num2=5):
#     my_sum = num1 + num2
#     return my_sum
#
#
# add1 = my_add(10)
# add2 = my_add(12, 10)
#
# print(add1)
# print(add2)

# 匿名函数 lambda   只有一行代码时定义
# lambda 参数列:表达式
# lambda a, b: a + b
# l = lambda a: a * a
# m = l(10)
# print(m)


# num1 = 5
# a = 1
# for i in range(5):
#     a = a * num1
#     num1 -= 1
#
# print(a)


# 函数计算阶层,函数递归
# def jc(n):
#     if n > 1:
#         return n * jc(n - 1)
#     else:
#         return 1
#
#
# a = jc(5)
# print(a)


# 函数中定义一个函数，且将该函数返回：函数的闭包
# def out(m):
#     print("一级函数")
#     print(m)
#
#     def inner(n):
#         print("内部函数")
#         print(n+m)
#
#     return inner
#
#
# out(10)(20)
# print(out())


# def jia(num1, num2):
#     return num1 + num2
#
#
# def jian(num1, num2):
#     return num1 - num2
#
#
# def cheng(num1, num2):
#     return num1 * num2
#
#
# def chu(num1, num2):
#     return num1 / num2
#
#
# # *args 不定长元组，**kwargs 不定长字典
# def out(f):
#     print("一级函数")
#     print(f)
#
#     def inner(*args, **kwargs):  # 接受任意参数
#         print("内部函数")
#         return f(*args, **kwargs)
#
#     return inner
#
#
# a = out(jia)(1, 2)
#
# print(a)
#

# 1. 定义闭包 2.函数头上加装饰器
# 装饰器

def my_decorator(func):
    def wrapper(*args, **kwargs):
        print(f"调用函数{func}, 参数：{args}, {kwargs}")
        result = func(*args, **kwargs)
        print(f"函数{func}执行完毕，结果是：{result}")
        return result

    return wrapper


@my_decorator
def jia(num1, num2):
    return num1 + num2


@my_decorator
def jian(num1, num2):
    return num1 - num2


@my_decorator
def cheng(num1, num2):
    return num1 * num2


@my_decorator
def chu(num1, num2):
    return num1 / num2


a = jia(2, 6)
print(a)


# def decorator1(func):
#     def wrapper():
#         print("装饰器1开始")
#         func()
#         print("装饰器1结束")
#
#     return wrapper
#
#
# def decorator2(func):
#     def wrapper():
#         print("装饰器2开始")
#         func()
#         print("装饰器2结束")
#
#     return wrapper
#
#
# @decorator1
# @decorator2
# def greet():
#     print("Hello!")
#
#
# greet()
